Java EE and HTML5 Enterprise Application Development by John Brock & Arun Gupta & Geertjan Wielenga
Author:John Brock & Arun Gupta & Geertjan Wielenga [Brock, John & Gupta, Arun & Wielenga, Geertjan]
Language: eng
Format: epub
Tags: Java, Programming Languages, Computers, -, General, Enterprise Applications, Html
ISBN: 9780071823142
Google: NpCbAgAAQBAJ
Publisher: McGraw Hill Professional
Published: 2014-03-28T00:00:00+00:00
Listing 4-9 JavaScript Methods for WebSocket
Let’s take a closer look at the methods shown in Listing 4-9. Remember that during the initialization, you defined the new WebSocket object as a variable named websocket.
For websocket.onopen(evt) you are simply sending a message to the output variable saying that the connection was successful. This is the first event thrown by the WebSocket connection and is where you would do any additional setup code if you needed it.
For websocket.onclose(evt) you are going to check for the code given by the WebSocket protocol to help determine why the connection was closed. The tricky part with doing this is that the WebSocket specification (RFC 6455) says only that the endpoint “may” send a close code, not that it has to. If a code is sent, it should conform with one of the close codes defined in the IETF specification (http://tools.ietf.org/html/rfc6455#section-7.4). The recommended codes are listed and described (quoting RFC 6455) in Table 4-1. In the code for this game you are only going to check for a couple of specific codes, and just fall back to a generic message that shows the close code for anything else that may be sent by the endpoint. The check for close code 1006 is just in case the application tries to connect to the endpoint and it’s not there. You can’t use the onerror() event for this case because the WebSocket object is not completely created when this happens. It closes before it has been completely opened. The check for close code 1000 is to indicate that the New Game button was clicked and the websocket.close() method was called and processed successfully.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25285)
Hello! Python by Anthony Briggs(24338)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23431)
Kotlin in Action by Dmitry Jemerov(22510)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21973)
Dependency Injection in .NET by Mark Seemann(21844)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20709)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19522)
Grails in Action by Glen Smith Peter Ledbrook(18605)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17032)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15843)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13690)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11853)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11151)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10621)
Hit Refresh by Satya Nadella(9199)
The Kubernetes Operator Framework Book by Michael Dame(8570)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8400)
Robo-Advisor with Python by Aki Ranin(8360)